#include <iostream>


template<typename T>
class DynamicArray //类模板显示声明
{
public:
    DynamicArray():size(0),capacity(15)
    {
        a = new T[capacity];
    }

    void Insert(const T& value);

    //友元声明不会共享类的模板，友元声明也要声明模板
    //友元声明的模板不能和类模板重名
    template<typename U>
    friend std::ostream& operator<<(std::ostream& os,const DynamicArray<U> &da);
private:
    T *a;
    int size;
    int capacity;
};

template<typename T>
void DynamicArray<T>:: Insert(const T& value)
{
    if(size == capacity)
    {   
        capacity *= 2;
        T *newP = new T[capacity];
        for(int i = 0;i < size;i++)
        {
            newP[i] = a[i];
        }
        delete []a;
        a = newP;
    }

    a[size++] = value;
}

template<typename T>
std::ostream& operator<<(std::ostream& os,const DynamicArray<T> &da)
{
    for(int i = 0;i < da.size;i++)
    {
        std::cout<<da.a[i]<<" ";
    }
    os<<std::endl;
    return os;
}

